home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / dict / dt.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  2KB  |  104 lines

  1.  
  2. #include <LEDA/dictionary.h>
  3.  
  4. #include <LEDA/impl/ch_hash.h>
  5. #include <LEDA/impl/ch_hash1.h>
  6.  
  7.  
  8. void dic_test(dictionary<int,int>& D, int N, int* A, char* name)
  9.   cout << string("%-12s",name);
  10.   cout.flush();
  11.  
  12.   float T;
  13.   float T0 = T = used_time();
  14.  
  15.   for(int i=0; i<N; i++)  D.insert(A[i],0);
  16.   cout << string("%10.2f",used_time(T));
  17.   cout.flush();
  18.  
  19.   for(i=0; i<N; i++)  
  20.   { dic_item it = D.lookup(A[i]);
  21.     if (it == nil || D.key(it) != A[i]) error_handler(1,"error in lookup");
  22.    }
  23.  
  24.   cout << string("%10.2f",used_time(T));
  25.   cout.flush();
  26.  
  27.   for(i=0; i<N; i++)  D.del(A[i]);
  28.   cout << string("%10.2f",used_time(T));
  29.  
  30.   cout << string("%10.2f",used_time(T0));
  31.  
  32.   if (!D.empty()) cout << " NOT EMPTY !!\n";    
  33.  
  34.   newline;
  35.  
  36.   //memory_clear();
  37.  
  38. }
  39.  
  40.  
  41. void dic_test(dictionary<float,float>& D, int N, float* A, char* name)
  42.   cout << string("%-12s",name);
  43.   cout.flush();
  44.  
  45.   D.clear();
  46.  
  47.   float T;
  48.   float T0 = T = used_time();
  49.  
  50.  
  51.   for(int i=0; i<N; i++)  D.insert(A[i],0);
  52.   cout << string("%10.2f",used_time(T));
  53.   cout.flush();
  54.  
  55.   for(i=0; i<N; i++)  D.lookup(A[i]);
  56.   cout << string("%10.2f",used_time(T));
  57.   cout.flush();
  58.  
  59.   for(i=0; i<N; i++)  D.del(A[i]);
  60.   cout << string("%10.2f",used_time(T));
  61.  
  62.   cout << string("%10.2f",used_time(T0));
  63.   newline;
  64.  
  65.   //memory_clear();
  66. }
  67.  
  68.  
  69.  
  70. main()
  71. {
  72.  
  73.   _dictionary<int,int,ch_hash> CHH_DIC;
  74.   _dictionary<int,int,ch_hash1> CH1_DIC;
  75.  
  76.   int    N     = read_int("# keys = ");
  77.   int*   Int   = new int[N];
  78.   int*   Int1  = new int[N];
  79.  
  80.   //init_random(N);
  81.  
  82.   float T = used_time();
  83.   for(int i=0; i<N; i++) Int[i] = random(1,10000000);
  84.   cout << string(" init time1 = %.2f sec",used_time(T)) << endl;
  85.  
  86.   for(i=0; i<N; i++) Int1[i] = i;
  87.   cout << string(" init time2 = %.2f sec",used_time(T)) << endl;
  88.  
  89.  
  90.   newline;
  91.   cout << "                insert    lookup    delete     total\n";
  92.   newline;
  93.  
  94.  
  95.   dic_test(CHH_DIC,N,Int,"ch_hash");
  96.   dic_test(CH1_DIC,N,Int,"ch_hash1");
  97.  
  98.   return 0;
  99. }
  100.  
  101.  
  102.